package com.neusoft.pub.cloud.provider.entity;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {

    private int pageNumber;

    private int pageSize;

    private List<T> pageData;

    private long total;

    public Page() {
        pageData = new ArrayList<>();
    }

    /**
     * list转分页
     * @param pageNumber
     * @param pageSize
     * @param list
     */
    public Page(Integer pageNumber, Integer pageSize, List<T> list) {
        int startIndex = (pageNumber - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, list.size());
        List<T> sublist = list.subList(startIndex, endIndex);
        this.setPageNumber(pageNumber);
        this.setPageSize(pageSize);
        this.setPageData(sublist);
        this.setTotal(list.size());
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getPageData() {
        return pageData;
    }

    public void setPageData(List<T> pageData) {
        this.pageData = pageData;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }
}
